package com.ngc.mall.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ngc.mall.domain.UserCouponDomain;
import com.ngc.mall.vo.UserCouponSimplifyVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserCouponMapper extends BaseMapper<UserCouponDomain> {

    @Select("select u.id as userId,u.nickname as userName,c.coupon_id as couponId,c.create_time as createTime,c1.name as couponName from wx_user u left join user_coupon c on u.id=c.user_id left join coupon c1 on c.coupon_id=c1.id ORDER BY c.create_time DESC;")
    List<UserCouponSimplifyVO> findAllCollectRecord();

    @Update("update user_coupon uc set uc.status=2,uc.order_id=#{oid} where uc.status=1 and uc.user_id=#{uid} and uc.coupon_id=#{couponId} and uc.oid is null")
    Boolean writeOff(Long couponId, Long uid, Long oid);
}
